package com.group01.community.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group01.community.entity.SysUser;
import com.group01.community.entity.vo.SysUserInfoVo;
import com.group01.community.entity.vo.SysUserVo;
import com.group01.community.mapper.SysUserMapper;
import com.group01.community.service.SysUserService;
import com.group01.community.utils.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author iuoly
 * @since 2022-07-04
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public void insertBatch(List<SysUser> sysUsers) {
        for (SysUser sysUser : sysUsers) {
            if (!ExcelUtils.isAllFieldNull(sysUser)) {
                sysUserMapper.insertBatch(sysUser);
            }
        }
    }

    @Override
    public SysUser selectRoleByUserId(Long userId) {
        return sysUserMapper.selectRoleByUserId(userId);
    }

    @Override
    public SysUserVo getUserRoleByUsername(String username) {
        return sysUserMapper.selectUserRoleByUsername(username);
    }

    @Override
    public SysUserInfoVo getUserInfoByUserName(String username) {
        return sysUserMapper.getUserInfoByUserName(username);
    }

    @Override
    public void updateUserInfo(SysUser sysUser) {
        sysUserMapper.updateUserInfo(sysUser);
    }

    @Override
    public List<SysUser> getDeptUserByDeptId(Long deptId) {
        return sysUserMapper.getDeptUserByDeptId(deptId);
    }

    @Override
    public IPage<SysUserInfoVo> selectUserPage(Long current, Long size, SysUser user) {
        return sysUserMapper.selectUserPage(new Page<>(current, size), user);
    }

    @Override
    public void updatePassword(String password) {
        sysUserMapper.updatePassword(password);
    }
}
